const EventEmitter = require('events');

class MyEmitter extends EventEmitter {}

const myEmitter = new MyEmitter();

let count = 0;

// 绑定事件监听
myEmitter.on('log', () => {
  count++;
  console.log(`${count}. mitter 触发 "log" 事件 ${new Date()}`);
});

const intervalId = setInterval(() => {
  // 触发事件
  myEmitter.emit('log');
  if (count === 3) {
    clearInterval(intervalId);
  }
}, 1000);

console.log('----');
